<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>网上书店</title>

		<link rel="stylesheet" href="css/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="css/style.css">
		<script src="js/app.js" charset="UTF-8"></script>
		<script src="js/vue.js"></script>
		<script src="js/axios.min.js"></script>
		<script src="js/vue-cookies.js"></script>
		<script src="css/layui/layui.js" charset="utf-8"></script>
		<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
	</head>
	<body>
		<div id="app">
			<div style="width:300px;height:300px;margin-left:20px;margin-top:100px;">
				店铺名:<input v-model="shopName"  style="width:200px;display: inline;"class="layui-input" placeholder="请输入店铺名"/>
						<button @click="application"class="layui-btn layui-btn-danger" style="margin-top:100px;margin-left:45px;line-height:0px;height:30px;width:180px;float:left;">申请店铺</button>
			</div>
		</div>



		<!-- 搜索框 -->





		<script type="text/javascript">
			var vm = new Vue({
				el: '#app',
				data: {
					username: '',
					loginflag: false,
					shoppinglist: '',
shopName:'',

				},

				methods: {
application:function(){
	let param = new URLSearchParams()
	param.append('userId', $cookies.get("userId"))
	param.append('passWord', $cookies.get("passWord"))
	param.append('userName', $cookies.get("userName"))
	param.append('shopName', vm.shopName)

	console.log(param.toString())

	if(vm.shopName=='')
	{
		layui.use('layer', function(){
			layer.msg("店铺名不能为空",{icon: 2})
		});
	}
	else
	{
		axios.post(URL + '/shop/shopApplication', param)
		.then(function(response) {			
			if (response.data.code == 1) {
					layui.use('layer', function(){
						layer.msg("店铺申请成功，导航栏中已增加“创建商品”和“商家订单”功能。",{offset: ['140px', '0px']})
						setTimeout(function(){layer.closeAll(),parent.location.reload();}, 3000);
					});
										
			} else if (response.data.code == 0) {
				layui.use('layer', function(){
					layer.msg("申请店铺失败，可能有重名。",{offset: ['140px', '35px']})
					setTimeout(function(){layer.closeAll(),parent.location.reload();}, 1000);
				});
			}
		})
		.catch(function(error) {
			console.log(error);
		});
	}
	
}
				},
				created: function() {
					// checklogin()
					checklogin().then(x => {
						if (x) {
							if ($cookies.get("userName") != null)
								this.username = $cookies.get("userName")
							if ($cookies.get("userShowName") !== null)
								this.userShowName = $cookies.get("userShowName");
							this.loginflag = $cookies.get("loginflag")
						}
						else{
							layui.use('layer', function() {
								var layer = layui.layer;
								layer.open({
									title: "提示" //不显示标题栏
										,
									closeBtn: false,
									shade: 0.8,
									id: 'LAY_layuipro' //设定一个id，防止重复弹出
										,
									btn: ['确认', '取消'],
									btnAlign: 'c',
									moveType: 1 //拖拽模式，0或者1
										,
									type: 0,
									content: '请先登录再使用注册商店功能',
									yes: function(index, layero) {
										window.location.href = 'login.html'
										layer.close(index);
									},
									btn2: function(index, layero) {
										window.location.href = 'index.html'
									}
								});
							});
						}
					})
				
					
				},

			})
		</script>


		<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
		<script>
			layui.use('element', function() {
				var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块

				//监听导航点击
				element.on('nav(demo)', function(elem) {
					//console.log(elem)
					layer.msg(elem.text());
				});
			})
		</script>

	</body>
</html>
